package com.example.server.controller;

import com.example.server.domain.BuildingStudents;
import com.example.server.domain.Dorms;
import com.example.server.service.DormsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@Controller
//@CrossOrigin(origins = "*",allowCredentials = "true",allowedHeaders = "*",methods = {RequestMethod.GET,RequestMethod.POST,RequestMethod.DELETE,RequestMethod.PUT,RequestMethod.OPTIONS})
@RequestMapping("/dorms")
public class DormsController {
    private final DormsService dormsService;

    public DormsController(DormsService dormsService) {
        this.dormsService = dormsService;
    }



    @RequestMapping("/create")
    @ResponseBody
    public void createDorm(@RequestBody Dorms dorms) {
        dormsService.createDorm(dorms);
    }
    @RequestMapping("/delete")
    @ResponseBody
    public void deleteDorm(Long id) {
        dormsService.deleteDorm(id);
    }
    @RequestMapping("/querybyid")
    @ResponseBody
    public Dorms getDormById(Long id) {
        return dormsService.getDormById(id);
    }
    @RequestMapping("/update")
    @ResponseBody
    public void updateDorm(@RequestBody Dorms dorms) {
         dormsService.updateDorm(dorms);
    }
    @RequestMapping("/queryall")
    @ResponseBody
    public List<Dorms> getAllDorms() {
        return dormsService.getAllDorms();
    }

    @RequestMapping("/queryByRoom")
    @ResponseBody
    public Dorms queryByRoom(String room) {
        return dormsService.queryByRoom(room);
    }



    @RequestMapping("/summary")
    @ResponseBody
    public List<BuildingStudents> summary() {
        return dormsService.summary();
    }
}
